package com.google.code.alpaca.example.server.handler;

import net.customware.gwt.dispatch.server.ActionHandler;
import net.customware.gwt.dispatch.server.ExecutionContext;
import net.customware.gwt.dispatch.shared.DispatchException;

import com.google.code.alpaca.example.rpc.MessageAction;
import com.google.code.alpaca.example.rpc.MessageResult;
import com.google.code.alpaca.example.server.MessageRepository;

public class MessageHandler implements ActionHandler<MessageAction, MessageResult> {
  
  private MessageRepository messageRepository = new MessageRepository();

  @Override
  public Class<MessageAction> getActionType() {
    return MessageAction.class;
  }

  @Override
  public MessageResult execute(MessageAction action, ExecutionContext context)
      throws DispatchException {
    MessageResult result = new MessageResult();
    result.setAllMessages(messageRepository.getAll());
    return result;
  }

  @Override
  public void rollback(MessageAction action, MessageResult result,
      ExecutionContext context) throws DispatchException {
  }

}
